home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tclsrc / globrecur.tcl < prev    next >
Encoding:
Text File  |  1993-11-19  |  2.5 KB  |  75 lines

  1. #
  2. # globrecur.tcl --
  3. #
  4. #  Build or process a directory list recursively.
  5. #------------------------------------------------------------------------------
  6. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: globrecur.tcl,v 3.0 1993/11/19 07:00:29 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. #@package: TclX-globrecur recursive_glob
  20.  
  21. proc recursive_glob {dirlist globlist} {
  22.     set result {}
  23.     set recurse {}
  24.     foreach dir $dirlist {
  25.         if ![file isdirectory $dir] {
  26.             error "\"$dir\" is not a directory"
  27.         }
  28.         foreach pattern $globlist {
  29.             set result [concat $result [glob -nocomplain -- $dir/$pattern]]
  30.         }
  31.         foreach file [glob -nocomplain -- $dir/* $dir/.*] {
  32.             if [file isdirectory $file] {
  33.                 set fileTail [file tail $file]
  34.                 if {!(($fileTail == ".") || ($fileTail == ".."))} {
  35.                     lappend recurse $file
  36.                 }
  37.             }
  38.         }
  39.     }
  40.     if ![lempty $recurse] {
  41.         set result [concat $result [recursive_glob $recurse $globlist]]
  42.     }
  43.     return $result
  44. }
  45.  
  46. #@package: TclX-forrecur for_recursive_glob
  47.  
  48. proc for_recursive_glob {var dirlist globlist code {depth 1}} {
  49.     upvar $depth $var myVar
  50.     set recurse {}
  51.     foreach dir $dirlist {
  52.         if ![file isdirectory $dir] {
  53.             error "\"$dir\" is not a directory"
  54.         }
  55.         foreach pattern $globlist {
  56.             foreach file [glob -nocomplain -- $dir/$pattern] {
  57.                 set myVar $file
  58.                 uplevel $depth $code
  59.             }
  60.         }
  61.         foreach file [glob -nocomplain -- $dir/* $dir/.*] {
  62.             if [file isdirectory $file] {
  63.                 set fileTail [file tail $file]
  64.                 if {!(($fileTail == ".") || ($fileTail == ".."))} {
  65.                     lappend recurse $file
  66.                 }
  67.             }
  68.         }
  69.     }
  70.     if ![lempty $recurse] {
  71.         for_recursive_glob $var $recurse $globlist $code [expr {$depth + 1}]
  72.     }
  73.     return {}
  74. }
  75.